<?php
if(isset($_GET['lettre'])){
	$Lettre=$_GET['lettre'];
	}
else{
	$Lettre="A";
	}
if(isset($_GET['List'])){
	$ListR=$_GET['List'];
	$UrlRL="&List=".$ListR;
}
else{
	$ListR='';
	$UrlRL="";
	}
	
if(isset($_GET['Etat'])){
	$EtatER=$_GET['Etat'];
	$UrlER="&Etat=".$EtatER;
}
else{
	$EtatER='';
	$UrlER='';
	}
?>

<div id="ContainAdmin">
	<div id="TitreAdmin"></div>
	<div id="LeftAdmin"><font class="TitleCompte">Emails inscris dans la newsletter CONCRETE:</font>
	<div class="Lettre">

	  <a href="index.php?page=emails&lettre=0">0</a>-<a href="index.php?page=emails&lettre=1">1</a>-<a href="index.php?page=emails&lettre=2">2</a>-<a href="index.php?page=emails&lettre=3">3</a>-<a href="index.php?page=emails&lettre=4">4</a>-<a href="index.php?page=emails&lettre=5">5</a>-<a href="index.php?page=emails&lettre=6">6</a>-<a href="index.php?page=emails&lettre=7">7</a>-<a href="index.php?page=emails&lettre=8">8</a>-<a href="index.php?page=emails&lettre=9">9</a><br>
	  <a href="index.php?page=emails&lettre=a<?php echo $UrlRL.$UrlER; ?>">A</a>-<a href="index.php?page=emails&lettre=b<?php echo $UrlRL.$UrlER; ?>">B</a>-<a href="index.php?page=emails&lettre=c<?php echo $UrlRL.$UrlER; ?>">C</a>-<a href="index.php?page=emails&lettre=d<?php echo $UrlRL.$UrlER; ?>">D</a>-<a href="index.php?page=emails&lettre=e<?php echo $UrlRL.$UrlER; ?>">E</a>-<a href="index.php?page=emails&lettre=f<?php echo $UrlRL.$UrlER; ?>">F</a>-<a href="index.php?page=emails&lettre=g<?php echo $UrlRL.$UrlER; ?>">G</a>-<a href="index.php?page=emails&lettre=h<?php echo $UrlRL.$UrlER; ?>">H</a>-<a href="index.php?page=emails&lettre=i<?php echo $UrlRL.$UrlER; ?>">I</a>-<a href="index.php?page=emails&lettre=j<?php echo $UrlRL.$UrlER; ?>">J</a>-<a href="index.php?page=emails&lettre=k<?php echo $UrlRL.$UrlER; ?>">K</a>-<a href="index.php?page=emails&lettre=l<?php echo $UrlRL.$UrlER; ?>">L</a>-<a href="index.php?page=emails&lettre=m<?php echo $UrlRL.$UrlER; ?>">M</a>-<a href="index.php?page=emails&lettre=n<?php echo $UrlRL.$UrlER; ?>">N</a>-<a href="index.php?page=emails&lettre=o<?php echo $UrlRL.$UrlER; ?>">O</a>-<a href="index.php?page=emails&lettre=p<?php echo $UrlRL.$UrlER; ?>">P</a>-<a href="index.php?page=emails&lettre=q<?php echo $UrlRL.$UrlER; ?>">Q</a>-<a href="index.php?page=emails&lettre=r<?php echo $UrlRL.$UrlER; ?>">R</a>-<a href="index.php?page=emails&lettre=s<?php echo $UrlRL.$UrlER; ?>">S</a>-<a href="index.php?page=emails&lettre=t<?php echo $UrlRL.$UrlER; ?>">T</a>-<a href="index.php?page=emails&lettre=u<?php echo $UrlRL.$UrlER; ?>">U</a>-<a href="index.php?page=emails&lettre=v<?php echo $UrlRL.$UrlER; ?>">V</a>-<a href="index.php?page=emails&lettre=w<?php echo $UrlRL.$UrlER; ?>">W</a>-<a href="index.php?page=emails&lettre=x<?php echo $UrlRL.$UrlER; ?>">X</a>-<a href="index.php?page=emails&lettre=y<?php echo $UrlRL.$UrlER; ?>">Y</a>-<a href="index.php?page=emails&lettre=z<?php echo $UrlRL.$UrlER; ?>">Z</a>
	</div>
	<?php
	//CLASSEMENT PAR LISTING----------------
	$recupList=mysql_query("SELECT * FROM listing  ORDER BY Listing") or die("prob de sel des users");
	$nbuserNews=mysql_num_rows($recupList);
	if($nbuserNews>0){
	?>
	<div class="Lettre">
	<?php
	while($dataRL= mysql_fetch_array($recupList)){
	$idListing=$dataRL['idListing'];
	$Listing=$dataRL['Listing'];
	$UrlRL2="&List=".$idListing;
	echo "<a href='index.php?page=emails&lettre=".$Lettre."".$UrlRL2.$UrlER."'>".$Listing."</a> | ";
	}
	?>
	</div>
	<?php } ?>
	<div class="Lettre">
	<?php echo "<a href='index.php?page=emails&lettre=".$Lettre."".$UrlRL."&Etat=oui'>Actif</a> | <a href='index.php?page=emails&lettre=".$Lettre."".$UrlRL."&Etat=non'>Mise en veille</a>"; ?>
	</div>
<table width="422" border="0" cellspacing="0" cellpadding="0">
<?php
	$idAdmin=$_SESSION['id'];
	if(!empty($ListR) && empty($EtatER)){
	$SearchList="WHERE Listing='$ListR'";
	}
	else{
			if(empty($ListR) && !empty($EtatER)){
			$SearchList="WHERE Etat='$EtatER'";
			}
			else{
				if(!empty($ListR) && !empty($EtatER)){
				$SearchList="WHERE Etat='$EtatER' AND Listing='$ListR'";
				}
				else{
				$SearchList='';
				}
			}
		}
	$req1=mysql_query("SELECT * FROM recupemails $SearchList ORDER BY Email") or die("prob de sel des users");
	$nbuserNews=mysql_num_rows($req1);
	$i=0;
	?>
	<tr><td> <strong>
<?php echo '<br>'.$nbuserNews.' emails'; ?></strong>
<br><br></td><td></td><td></td></tr>
	<?php
	while($data= mysql_fetch_array($req1)){
	$idNews=$data['idEmail'];
	$EmailNews=$data['Email'];
	$Etat=$data['Etat'];
	?>
	<?php
	$VerifEmail=substr($EmailNews,0,1);
	if(isset($_GET['lettre'])){
	$Lettre=$_GET['lettre'];
	}
	else{
	$Lettre="A";
	}
	if(($VerifEmail==$Lettre) || (strtoupper($VerifEmail)==strtoupper($Lettre))){
	$i++;
	if($i&1){
	$color="background-color:#F0F0F0;";
	}
	else{
	$color="";
	}
	if($Etat=="oui"){
	$Etat="color:#035507;";
	}
	if($Etat=="non"){
	$Etat="color:#5E1302;";
	}
	?>
  <tr>

    <td width="358" align="left" valign="middle" style="padding:5px 0 2px 0; <?php echo $color.' '.$Etat; ?> ">
	
	<img src="./images/Arrow.png" alt=">"><?php echo $EmailNews; ?></td>
	<form action="" method="post">
	<input name="idNewsMod" type="hidden"  value="<?php echo $idNews ?>">
	<input name="EmailNewsMod" type="hidden" value="<?php echo $EmailNews; ?>">
	<td width="32" style="padding:5px 0 2px 0; <?php echo $color; ?> "><input name="Envoyer" type="image" img src="./images/BtnModif.png" value="Modifier" class="modif"></td>
	</form>

	<form  method="post" action="" >
	<input name="idNewsSup" type="hidden"  value="<?php echo $idNews ?>">
	<input name="EmailNewsSup" type="hidden"  value="<?php echo $EmailNews; ?>">
    <td width="32" style="padding:5px 0 2px 0; <?php echo $color; ?> ">
	<input name="Envoyer" type="image" img src="./images/BtnSup.png" value="Modifier" class="modif">
	</td>
	</form>
  </tr>
  <?php  
  }
  }
   ?>
</table>


	</div>
	<div id="RightAdmin"><font class="TitleCompte">Ajouter un mail &agrave; la newsletter CONCRETE:</font><br>
	  <br>
	<?php include('app/AjoutEmail.php'); ?>
<div class="ModifEmail">
<?php 
if(isset($_POST['EmailNewsMod'])){
include("app/ModifEmails.php");
} 
if(isset($_POST['idNewsSup'])){
include("app/SupEmails.php");
} 
?>
</div>
	</div>
	<div class="clr"></div>
</div>